Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add declarative validation for Fabric network config files #595

Merged

Conversation

aklenik
Copy link
Contributor

@aklenik aklenik commented Sep 30, 2019

Signed-off-by: Attila Klenik [email protected]

Resolves part of issue #467
(Also moves the config runtime key names, so the Config.js module can use them without a circular dep issue.)

Design of the fix

The validation part of the fabricNetwork.js module was extracted into configValidator.js, which uses the joi package to define and validate object schemas declaratively. This makes it easy to adapt the validation rule for future/changed schemas.

Validation of the fix

Unit tests cover the entire schema, property-by-property (since the schema is declarative, code coverage is not representative). The expected error/joi messages are checked to ensure that the test targets the intended property error (and isn't masked by an other error).

Automated Tests

What documentation has been provided for this pull request

Even though this is just an under-the-hood change, the Fabric adapter docs is also updated to make it more readable and consistent with the validation rules. Live preview: https://aklenik.github.io/caliper/vNext/fabric-config/

Copy link
Contributor

@nklincoln nklincoln left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+bazillion for the comprehensive testing with the code 👍

Might be worth using the same joi based validation for the config file too?

@aklenik
Copy link
Contributor Author

aklenik commented Oct 2, 2019

+bazillion for the comprehensive testing with the code 👍

Might be worth using the same joi based validation for the config file too?

Yes, that's also what I had in mind. Plus, Joi schemas are "compiled" and can be reused.
So this means we could also use them for basic stuffs, like input validation in different functions, in a self-documenting way. This could definitely improve the readability for cold paths.
(But who knows, maybe it's fast enough also for hot paths)

@aklenik aklenik merged commit cdd1a0b into hyperledger-caliper:master Oct 2, 2019
@aklenik aklenik deleted the fabric-network-validation branch October 2, 2019 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR/under review The PR is currently under review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants